package org.eclipse.emf.cdo.ui.merge;

import java.util.ArrayList;

import org.eclipse.emf.cdo.ui.merge.TreeObject;


/**
 * The basic node of the tree. It is an extension of a normal tree-leaf (TreeObject) 
 * adding the possibility to add children (nodes or leafs).
 * Including functionalities to add or remove nodes.
 * @author Thomas Halmetschlager
 */
public class TreeParent extends TreeObject {
	
	/** The list of children. */
	private ArrayList children;
	
	/**
	 * Instantiates a new tree parent.
	 *
	 * @param name of the node.
	 */
	public TreeParent(String name) {
		super(name);
		children = new ArrayList();
	}
	
	/**
	 * Adds a child.
	 *
	 * @param child the child to add
	 */
	public void addChild(TreeObject child) {
		children.add(child);
		child.setParent(this);
	}
	
	/**
	 * Removes the given TreeObject.
	 *
	 * @param child the TreeObject to remove
	 */
	public void removeChild(TreeObject child) {
		children.remove(child);
		child.setParent(null);
	}
	
	/**
	 * Returns all children.
	 *
	 * @return the children
	 */
	public TreeObject [] getChildren() {
		return (TreeObject [])children.toArray(new TreeObject[children.size()]);
	}
	
	/**
	 * Checks for children.
	 *
	 * @return true, if there are any.
	 */
	public boolean hasChildren() {
		return children.size()>0;
	}
}